package demo2;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 晓星航
 * Date: 2022-11-16
 * Time: 19:38
 */
class Animal {
    protected  String name;

    public  Animal(String name) {
        this.name = name;
    }
}
class Dog extends Animal {
    public Dog(String name){
        super(name);
    }
}
//不是所有的动物都会飞，所以，不能写到Animal类当中
interface IFlying {
    void fly();
}
class Bird extends Animal implements IFlying{
    public Bird(String name) {
        super(name);
    }

    @Override
    public void fly() {
        System.out.println(this.name + "正在飞！");
    }
}
interface IJumpping {
    void jump();
}
interface ISwimming {
    void swim();
}
interface IRunning {
    void run();
}
class Frog extends Animal implements IJumpping,ISwimming,IRunning{
    public Frog(String name) {
        super(name);
    }

    @Override
    public void run() {
        System.out.println(this.name + "正在跑");
    }

    @Override
    public void jump() {
        System.out.println(this.name + "正在跳！");
    }

    @Override
    public void swim() {
        System.out.println(this.name + "正在游泳！");
    }
}
class Duck extends Animal implements IFlying,ISwimming,IJumpping,IRunning{
    public Duck(String name) {
        super(name);
    }

    @Override
    public void fly() {
        System.out.println(this.name + "正在飞");
    }

    @Override
    public void jump() {
        System.out.println(this.name + "正在跳");
    }

    @Override
    public void swim() {
        System.out.println(this.name + "正在游泳");
    }

    @Override
    public void run() {
        System.out.println(this.name + "正在跑");
    }
}
class Robot implements IRunning {
    @Override
    public void run() {
        System.out.println("机器人在跑");
    }
}
public class Test4 {
    public static void runFunc(IRunning iRunning) {
        iRunning.run();
    }
    public static void swimmingFunc(ISwimming iSwimming) {
        iSwimming.swim();
    }
    public static void flyingFunc(IFlying iFlying) {
        iFlying.fly();
    }
    public static void jumppingFunc(IJumpping jumpping) {
        jumpping.jump();
    }
    public static void main(String[] args) {
        runFunc(new Duck("鸭子"));
        runFunc(new Frog("青蛙"));
        swimmingFunc(new Duck("鸭子"));
        flyingFunc(new Duck("鸭子"));
        flyingFunc(new Bird("小鸟"));
        jumppingFunc(new Frog("青蛙"));
        runFunc(new Robot());
    }
}


